//官方圈子-模板

//引入组件库
var app = sm("do_App");
var page = sm("do_Page");
var nf = sm("do_Notification");
var circleUrl = require("url/circle");
var http = require("helper/http");
var userUtil = require("helper/user");
var circleHelper = require("helper/circle");

//声明UI变量
var root=ui("$");  //$表示当前视图的根UI
//var do_ALayout_main=ui("do_ALayout_main");
var do_ImageView_icon=ui("do_ImageView_icon");
var do_Label_title=ui("do_Label_title");
var do_Label_desc=ui("do_Label_desc");

//设置数据绑定的映射关系
root.setMapping({
	"do_Label_title.tag":"id",
	"do_Label_title.text":"name",
	"do_Label_desc.text":"remark",
	"do_ImageView_icon.source":"fullLogo",
	"do_Button_join.visible":"canJion"
});

var do_Button_join = ui("do_Button_join");
do_Button_join.on("touch", function(data, e) {
	if(userUtil.loginToken()===""){
		nf.alert("您还没有登录哦.");
	}else{
		do_Button_join.hide();
		var circleId = do_Label_title.tag;
		http.post(circleUrl.url.member.joinCircle,{"circleId":circleId},function(data){
			//deviceone.print(JSON.stringify(data))
			if(data.myMsg){
				nf.toast(data.myMsg)
			}else{
				page.fire("join_circle_success", {"circleId":circleId});
				nf.toast("加入成功");
			}
		});
	}
})


//点击一个圈子
root.on("touch", function(data){
	var circleId = do_Label_title.tag;
	var circleName = do_Label_title.text;
	circleHelper.toCircleDetail(circleId,circleName);
});
